package familytree.yu.com.admin.web;

import familytree.yu.com.admin.api.entity.memberinfo.BaseMemberDetailInfoEntity;
import familytree.yu.com.admin.api.entity.memberinfo.BaseMemberLoginInfoEntity;
import familytree.yu.com.admin.api.repository.BaseMemberDetailInfoRepository;
import familytree.yu.com.admin.api.repository.BaseMemberLoginInfoRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;

import java.util.Date;

/**
 * @Author: yuyunbo
 * @Date: 2021/2/1 23:51
 * @Description:
 */
@Slf4j
@Configuration
public class AdminWebCommonLineApplication implements CommandLineRunner {

    @Autowired
    private BaseMemberLoginInfoRepository baseMemberLoginInfoRepository;

    @Autowired
    private BaseMemberDetailInfoRepository baseMemberDetailInfoRepository;

    @Override
    public void run(String... args) throws Exception {
//        inserTest();
    }

    private void inserTest() {
        BaseMemberLoginInfoEntity baseMemberLoginInfoEntity = BaseMemberLoginInfoEntity.builder().memberCode("1q2w3e4r")
                .memberPhone("18512540145").memberPassword("test").gmtCreated(new Date()).gmtCreatedBy("yuyunbo").build();

        baseMemberLoginInfoRepository.save(baseMemberLoginInfoEntity);
        Long id = baseMemberLoginInfoEntity.getId();
        log.info("is over id={}", id);
        PageRequest pageReques=PageRequest.of(0,10);
        Page<BaseMemberLoginInfoEntity> pageBean = baseMemberLoginInfoRepository.findAll(pageReques);
        pageBean.get().forEach(bean ->{
            log.info(bean.toString());
        });


        BaseMemberDetailInfoEntity baseMemberDetailInfoBo = BaseMemberDetailInfoEntity.builder().
                memberCode("1q2w3e4r").memberBirthday("2020-02-01").gmtCreated(new Date()).gmtCreatedBy("yuyunbo").build();
        baseMemberDetailInfoRepository.save(baseMemberDetailInfoBo);
        Long detailId = baseMemberDetailInfoBo.getId();

        log.info("is over detailId={}", detailId);
    }

}
